/*
** types.h for types in /home/ricard_v//rack/zappy/zappy-2011/new_server/inc
** 
** Made by vincent ricard
** Login   <ricard_v@epitech.net>
** 
** Started on  Sun Jul 10 22:08:52 2011 vincent ricard
** Last update Sun Jul 10 22:11:43 2011 vincent ricard
*/

#ifndef __TYPES_H__
# define __TYPES_H__

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/resource.h>
#include "team.h"
#include "parser.h"

# define	TRUE		1
# define	FALSE		0
# define	CONNECTED	1
# define	DISCONNECTED	0

typedef struct variables_server
{
  fd_set	master;
  fd_set	read_fds;
  fd_set	write_fds;
  int		fdmax;
  int		*tab;
  int		listener;
  /* newly accepted */
  int		newfd;
  char		buf[4096];
  int		nbytes;
  int		yes;
  int           inc;
  int		addrlen;
  /*iterator sur les sock */
  int		i;
  int		j;
  int		first_cmd;
  int		port;
  struct	sockaddr_in serveraddr;
  struct	sockaddr_in clientaddr;

  /*server params */
  t_server_params	*server_params;

  /* server team */
  Class_team	*list_team;
}		T_env;

void		init_env(T_env *e, t_server_params *params);
char		**args_to_tab(char **args, int nb_args);
int		initiate_team(t_server_params *server, char **names, int pos);
void		aff_params(t_server_params *server);
void		check_params(t_server_params *server);
void		parser(t_server_params *server, char **args, int nb_args);
void		read_buff_from_socket(T_env *e, int socket, t_server_params *p);
void		manage_cmd(T_env *e, int so, char *b, t_server_params *p);
void		set_fds(T_env *e);
void		set_socket(T_env *e);
void		loop(T_env *e, t_server_params *p);
int             getMaxFd();
int             Find_disconnected_socket(T_env *);
int             Find_first(T_env *);
int		Is_Connected(int *tab , int socket);
int             getMaxFd();
int		get_time();
Class_team	*add_team(Class_team *req, char *team);
void		add_player(T_env *e, char *team,  t_server_params *p);
Class_player    *add(Class_player *list_players, int socket);
t_good_request  *request_parser(char *, int t);
void		*add_request(Class_player *e, int socket, t_server_params  *p, T_env *);
void		bind_socket(T_env *e, t_server_params *p);
void		config_server(T_env *e, t_server_params *p);
int		current_time();
void		disconnect_socket(T_env *e);
void		display_team(Class_team *all_team, int max, T_env *e);
void		send_taille_map(int socket, t_server_params *p);
void		voidaff_error(char *msg);
void            *xmalloc(size_t size);

# endif		/* __TYPES_H__ */
